package year2019.month11.singleton;

/**
 * @desc 单例模式：懒汉模式
 * create on 2018/11/6 by watson
 */
public class LazySingleton {
    private String str;

    private static LazySingleton lazySingleton;

    private LazySingleton(String str){
        this.str = str;
    }

    public static synchronized LazySingleton getLazySingleton() {
        if (lazySingleton==null){
            lazySingleton = new LazySingleton(String.valueOf(System.currentTimeMillis()));
        }
        return lazySingleton;
    }

    public static LazySingleton getLazy() {
        if (lazySingleton==null){
            synchronized (LazySingleton.class){
                if (lazySingleton==null){
                    lazySingleton = new LazySingleton(String.valueOf(System.currentTimeMillis()));
                }
            }
        }
        return lazySingleton;
    }

    public String getStr() {
        return str;
    }

}
